package com.jiaai.web.zfp.privilege;


import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jiaai.auth.model.AccessUser;
import com.jiaai.exception.ServerException;
import com.jiaai.filter.aop.TokenIntercept;
import com.jiaai.gift.api.ICarApi;
import com.jiaai.gift.api.IGiftApi;
import com.jiaai.member.api.IWalletAPI;
import com.jiaai.util.RequestUtils;
import com.jiaai.util.RestResultGenerator;
import com.jiaai.vip.api.IVIPApi;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.CountDownLatch;

/**
 * class_name:ZVipController
 * describe:TODO
 * create_user:张昉平
 * create_date:2018/1/2
 * create_date:10:46
 */
@RestController
@RequestMapping("/api/v1/app/vip")
public class ZVipController {

    @Reference
    private IVIPApi iVipApi;
    @Reference
    private IWalletAPI iWalletAPI;
    @Reference
    private IGiftApi iGiftApi;
    @Reference
    private ICarApi iCarApi;
    @GetMapping("/list")
    @TokenIntercept
    public Object list()throws ServerException {
//        JSONArray ja = JSONArray.parseArray(JSONObject.toJSONString(iVipApi.fidByAll()));
//        final CountDownLatch countDownLatch = new CountDownLatch(ja.size());
//
//        for (int i = 0; i < ja.size(); i++){
//            JSONObject jo = ja.getJSONObject(i);
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    jo.put("cars", iCarApi.getVipCar(jo.getInteger("vipId")));
//                 //   jo.put("gifts", iGiftApi.getVipGifts(jo.getInteger("vipId")));
//                    countDownLatch.countDown();
//                }
//            }).start();
//        }
//        try {
//            countDownLatch.await();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//            return RestResultGenerator.genErrorResult("获取vip列表失败");
//        }
//        return  RestResultGenerator.genSuccessResult(ja);
        return null;
    }


}
